from common.base.base_handler import BaseHandler
from services.killer.model import Killer
from settings import settings


class KillerHandler(BaseHandler):
    __slots__ = ['model']

    async def handle_get_all_services(self, params: dict) -> list:
        self.model.update_pid_list()
        return list(settings.PIDS_SERVICES.keys())

    async def handle_switch_service(self, params: dict) -> bool:
        name, action = params['name'], params['action']
        self.model.make_action_to_service(name, action)
        return True

    def __init__(self):
        self.model = Killer()

        super(KillerHandler, self).__init__(request_queue_uuid=settings.KILLER_REQUEST_QUEUE)

        self.handle('get_all_services',  self.handle_get_all_services)
        self.handle('switch_service', self.handle_switch_service)
